< previous page page_800 next page >

Page 800
note.gif If you use a calculated field with a data control, it is best to use a label control to show the contents of the field. This prevents the user from attempting to update the field and causing an error. You could also use a text box with the locked property set to True. (You can learn more about the Data control and bound controls by reviewing Chapter 25, "The Data Control and Data-Bound Controls.") If you use a text box, you might want to change the background color to indicate to the user that the data cannot be edited. square.gif

Specifying Alternative Field Names
Listing C.2 created calculated fields to include in a recordset. For many applications, you will want to use a name for the field other than the one automatically created by the query engine.
You can change the syntax of the SELECT statement to give the calculated field a name. You assign a name by including the AS clause and the desired name after the definition of the field (refer to the second part of Listing C.3). If you want, you can also use this technique to assign a different name to a standard field.
Listing C.3 CUSTNAME.TXTAccessing a Calculated Field's Value and Naming the Field
'********************************************
'Set up the SELECT statement without the name
'********************************************
Dim NewDyn As RecordSet
SQL = "SELECT Lastname & ', ' & Firstname FROM Customers"
'****************************************
'Create a dynaset from the SQL statement
'****************************************
NewDyn = OldDb.OpenRecordset(SQL)
'**********************************
'Get the value of the created field
'**********************************
Person = NewDyn.Recordset(0)
'**********************************************************
'Set up the SELECT statement and assign a name to the field
'**********************************************************
SQL = "SELECT Lastname & ', ' & Firstname As Name FROM Customers"
'****************************************
'Create a dynaset from the SQL statement
'****************************************
NewDyn = OldDb.OpenRecordset(SQL)
'**********************************
'Get the value of the created field
'**********************************
Person = NewDyn.Recordset("Name")

 
< previous page page_800 next page >